package com.hscm.boss.common.events.listener;

import com.hscm.boss.common.events.model.NoticeUserPaymentEvent;
import com.hscm.boss.common.utils.mails.MailClient;
import com.hscm.boss.common.utils.mails.model.MailProperties;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;


@Component
public class NoticeMailListener implements ApplicationListener<NoticeUserPaymentEvent> {



    private Logger logger = LoggerFactory.getLogger(getClass());//获取当前类的日志
    @Resource
    private MailClient mailClient;


    @Async
    @Override
    public void onApplicationEvent(NoticeUserPaymentEvent event) {

        //处理邮件的发送事件
        MailProperties mailProperties = event.getMailProperties();

        boolean send = mailClient.sendAttachMail(mailProperties);
        //getId邮件的标识
        logger.info("发送邮件{}--{}",mailProperties.getId(),send);
    }
}
